<script lang="ts" setup>
import type { StudentsApi } from '#/api/edu/base/students';

import { ref } from 'vue';

import { useVbenDrawer } from '@vben/common-ui';

import { getStudents } from '#/api/edu/base/students';
import { useDescription } from '#/components/description';

import { useDetailSchema } from '../data';

const formData = ref<StudentsApi.Students>();

const [Descriptions] = useDescription({
  bordered: true,
  size: 'middle',
  column: 3,
  labelWidth: 120,
  schema: useDetailSchema(),
});

const [Drawer, drawerApi] = useVbenDrawer({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      return;
    }
    let data = drawerApi.getData<StudentsApi.Students>();
    if (!data || !data.studentsId) {
      return;
    }
    drawerApi.lock();
    try {
      data = await getStudents(data.studentsId);
      formData.value = data;
    } finally {
      drawerApi.unlock();
    }
  },
});
</script>

<template>
  <Drawer
    title="查看 学生基本信息"
    class="w-[80%]"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <Descriptions :data="formData" class="mx-4" />
  </Drawer>
</template>
